{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "# Scientific Programming in Python (SPiP) - Numpy Exercises\n",
    "\n",
    "\n",
    "by [Michael Granitzer (michael.granitzer@uni-passau.de)](http://www.mendeley.com/profiles/michael-granitzer/) \n",
    "\n",
    "[Konstantin Ziegler (konstantin.ziegler@uni-passau.de)](http://zieglerk.net)\n",
    "\n",
    "__License__\n",
    "\n",
    "\n",
    "This work is licensed under a [Creative Commons Attribution 3.0 Unported License](http://creativecommons.org/licenses/by/3.0/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Exercises\n",
    "\n",
    "Use the [Python 101 Cheatsheet](http://nbviewer.ipython.org/urls/bitbucket.org/hrojas/learn-pandas/raw/master/lessons/Python_101.ipynb) as reference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "##Exercise 3.1.a: Data Structures in Numpy\n",
    "\n",
    "  \n",
    "Given is the following table with data on when someone likes to play tennis.\n",
    "\n",
    "\n",
    "<table border=\"\" cellspacing=\"0\" width=\"48%\">\n",
    "  <tbody><tr>\n",
    "      <td><b>Day</b></td>\n",
    "      <td><b>outlook</b></td>\n",
    "      <td><b>temperature</b></td>\n",
    "      <td><b>humidity</b></td>\n",
    "      <td><b>windy</b></td>\n",
    "      <td><b>play</b></td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>1</td>\n",
    "      <td>sunny</td>\n",
    "      <td>85</td>\n",
    "\n",
    "      <td>85</td>\n",
    "\n",
    "      <td>false</td>\n",
    "\n",
    "      <td>no</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>2</td>\n",
    "\n",
    "      <td>sunny</td>\n",
    "\n",
    "      <td>80</td>\n",
    "\n",
    "      <td>90</td>\n",
    "\n",
    "      <td>true</td>\n",
    "\n",
    "      <td>no</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>3</td>\n",
    "\n",
    "      <td>overcast</td>\n",
    "\n",
    "      <td>83</td>\n",
    "\n",
    "      <td>86</td>\n",
    "\n",
    "      <td>false</td>\n",
    "\n",
    "      <td>yes</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>4</td>\n",
    "\n",
    "      <td>rainy</td>\n",
    "\n",
    "      <td>70</td>\n",
    "\n",
    "      <td>96</td>\n",
    "\n",
    "      <td>false</td>\n",
    "\n",
    "      <td>yes</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>5</td>\n",
    "\n",
    "      <td>rainy</td>\n",
    "\n",
    "      <td>68</td>\n",
    "\n",
    "      <td>80</td>\n",
    "\n",
    "      <td>false</td>\n",
    "\n",
    "      <td>yes</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>6</td>\n",
    "\n",
    "      <td>rainy</td>\n",
    "\n",
    "      <td>65</td>\n",
    "\n",
    "      <td>70</td>\n",
    "\n",
    "      <td>true</td>\n",
    "\n",
    "      <td>no</td>\n",
    "    </tr>\n",
    "\n",
    "    <tr>\n",
    "      <td>7</td>\n",
    "\n",
    "      <td>overcast</td>\n",
    "\n",
    "      <td>64</td>\n",
    "\n",
    "      <td>65</td>\n",
    "\n",
    "      <td>true</td>\n",
    "\n",
    "      <td>yes</td>\n",
    "    </tr>\n",
    "\n",
    "</tbody></table>\n",
    "\n",
    "\n",
    "* Represent the following table using numpy data structures (i.e. a list of numpy arrays or a dict of numpy arrays)\n",
    "* Given that data structure\n",
    "  - Calculate the mean temperature and mean humidity\n",
    "  - Print outlook and play for those days where the temperature is greater than the average temperature\n",
    "  - Print outlook and play for those days where the humidity is greater than the average humidity\n",
    "  - Convert the temperatur to celcius and add a new column therefore in the table. Use the following conversion equation $$ C=(F-32) *5/9$$\n",
    "  \n",
    "Note: You can take advantage of the already existing Python data structures from Exercise 2-1\n",
    "\n",
    "    data = [[1,\"sunny\",85,85,\"false\",\"no\"]\n",
    "       ,[2,\"sunny\",80,90,True,\"no\"]\n",
    "       ,[3,\"overcast\",83,86,False,\"yes\"]\n",
    "       ,[4,\"rainy\",70,96,False,\"yes\"]\n",
    "       ,[5,\"rainy\",68,80,False,\"yes\"]\n",
    "       ,[6,\"rainy\",65,70,True,\"no\"]\n",
    "       ,[7,\"overcast\",64,65,True,\"yes\"]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "##Exercise 3.1.b: Simple aggregations in Numpy\n",
    "\n",
    "Use the weather data from exercise 3.1.a and complete the following tasks using the numpy data structures:\n",
    "\n",
    "1. How often do you play tennis independent of the other attributes?\n",
    "2. How often do you play tennis when it is \"sunny\"?\n",
    "3. Compare the average, minimum and maximum temperature when you play tennis?\n",
    "4. Compare the average, minimum and maximum humidity when you play tennis?\n",
    "5. Plot the an scatter plot (x,y diagramm) of humidity (x) and temperatur (y) when you play tennis compared to when you do not play tennis. Use the following lines of code for a plot:\n",
    "\n",
    "     <pre><code>\n",
    "     %pylab inline\n",
    "     from pylab import *\n",
    "     figure()\n",
    "     plot(xdata,ydata)\n",
    "     title(\"Title goes here\")\n",
    "     show()</code></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "#Solutions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Solution 3.1.a: Data Structures in Numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([1, 2, 3, 4, 5, 6, 7]), array(['sunny', 'sunny', 'overcast', 'rainy', 'rainy', 'rainy', 'overcast'], \n",
      "      dtype='<U8'), array([85, 80, 83, 70, 68, 65, 64]), array([85, 90, 86, 96, 80, 70, 65]), array(['false', 'True', 'False', 'False', 'False', 'True', 'True'], \n",
      "      dtype='<U5'), array(['no', 'no', 'yes', 'yes', 'yes', 'no', 'yes'], \n",
      "      dtype='<U3')]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "labels = np.array([\"Day\",\t\"outlook\",\t\"temperature\",\t\"humidity\",\t\"windy\",\t\"play\"])\n",
    "data = [[1,\"sunny\",85,85,\"false\",\"no\"]\n",
    "   ,[2,\"sunny\",80,90,True,\"no\"]\n",
    "   ,[3,\"overcast\",83,86,False,\"yes\"]\n",
    "   ,[4,\"rainy\",70,96,False,\"yes\"]\n",
    "   ,[5,\"rainy\",68,80,False,\"yes\"]\n",
    "   ,[6,\"rainy\",65,70,True,\"no\"]\n",
    "   ,[7,\"overcast\",64,65,True,\"yes\"]]\n",
    "\n",
    "# iterate over all row and select the ith attribute where i goes from 0 to the number of columns\n",
    "res = [np.array([row[i] for row in data]) for i in range(len(data[0]))]\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [],
   "source": [
    "#define a helper function for less syntactic sugar\n",
    "def sel(attribute):\n",
    "    return np.where(labels==attribute)[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2]\n",
      "Mean temperatur=73.571429\n",
      "Mean humidity=81.714286\n",
      "Outlook for above average temperature: ['sunny' 'sunny' 'overcast']\n",
      "Play for above average temperature: ['no' 'no' 'yes']\n",
      "Outlook for above average humidty: ['sunny' 'sunny' 'overcast' 'rainy']\n",
      "Play for above average humidity: ['no' 'no' 'yes' 'yes']\n",
      "New Labels: ['Day' 'outlook' 'temperature' 'humidity' 'windy' 'play'\n",
      " 'temperaturCelsius']\n",
      "New Data: [array([1, 2, 3, 4, 5, 6, 7]), array(['sunny', 'sunny', 'overcast', 'rainy', 'rainy', 'rainy', 'overcast'], \n",
      "      dtype='<U8'), array([85, 80, 83, 70, 68, 65, 64]), array([85, 90, 86, 96, 80, 70, 65]), array(['false', 'True', 'False', 'False', 'False', 'True', 'True'], \n",
      "      dtype='<U5'), array(['no', 'no', 'yes', 'yes', 'yes', 'no', 'yes'], \n",
      "      dtype='<U3'), array([ 29.44444444,  26.66666667,  28.33333333,  21.11111111,\n",
      "        20.        ,  18.33333333,  17.77777778])]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:3: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "  app.launch_new_instance()\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:5: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:9: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:10: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:11: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:14: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:15: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:16: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:19: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n"
     ]
    }
   ],
   "source": [
    "#Calculate the mean temperature and mean humidity\n",
    "print(sel(\"temperature\"))\n",
    "mean_temp = res[sel(\"temperature\")].mean()\n",
    "print(\"Mean temperatur=%f\"%(mean_temp))\n",
    "mean_hum= res[sel(\"humidity\")].mean()\n",
    "print(\"Mean humidity=%f\"%(mean_hum))\n",
    "\n",
    "#Print outlook and play for those days where the temperature is greater than the average temperature\n",
    "idx = res[sel(\"temperature\")]>mean_temp\n",
    "print(\"Outlook for above average temperature:\",res[sel(\"outlook\")][idx])\n",
    "print(\"Play for above average temperature:\",res[sel(\"play\")][idx])\n",
    "\n",
    "#Print outlook and play for those days where the humidity is greater than the average humidity\n",
    "idx = res[sel(\"humidity\")]>mean_hum\n",
    "print(\"Outlook for above average humidty:\",res[sel(\"outlook\")][idx])\n",
    "print(\"Play for above average humidity:\",res[sel(\"play\")][idx])\n",
    "#Convert the temperatur to farenheit and add a new column therefore in the table. Use the following conversion equation\n",
    "#C=(F−32)∗5/9\n",
    "res.append((res[sel(\"temperature\")]-32.0)*5.0/9.0)\n",
    "labels = np.append(labels, [\"temperaturCelsius\"])\n",
    "print(\"New Labels:\", labels)\n",
    "print(\"New Data:\", res)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Solution 3.1.b: Simple aggregations in Numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I played tennis 4 times\n",
      "I played tennis 0 times when its sunny\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/zieglerk/local/share/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "  if __name__ == '__main__':\n",
      "/home/zieglerk/local/share/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:2: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    }
   ],
   "source": [
    "print(\"I played tennis %d times\"%np.sum(res[sel(\"play\")]==\"yes\"))\n",
    "print(\"I played tennis %d times when its sunny\"%np.sum(np.multiply(res[sel(\"play\")]==\"yes\",res[sel(\"outlook\")]==\"sunny\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "temperature mean=71.250000,min=64.000000,max=83.000000\n",
      "humidity mean=81.750000,min=65.000000,max=96.000000\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/zieglerk/local/share/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:2: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "  from ipykernel import kernelapp as app\n",
      "/home/zieglerk/local/share/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:5: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n",
      "/home/zieglerk/local/share/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:11: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEKCAYAAAAcgp5RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGt1JREFUeJzt3X+83dO95/HXO+JXNE2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nGgxsA1wALI+IiySdBwyPiCl9UqA26qEu/gboiojs71KqRdIgYAlwAHAWA7BddKuqi1MYQO1C0g7A\n/cCYiFgl6cfAbcDeDLA20Utd7EydbaJPevS9PFx1ODAzbTYTOKIvytNOftCsRwcDT0VEJwOwXVSp\nrAsYeO1iM2Cb1AnaGniOgdsmKutiCEVdQJ1toq+Gbnp6uGr77gu16U6d7fqoPO3kB81qOwaYk6YH\nYruodAxwXcX8gGkXEfE8cDHwLEWorYyIuxiAbaJGXaxIdQF1tom+Cvrqh6tep3i4qnrcaCBcGfaD\nZlUkbQ4cBtyQFg3EdgHUrIsB1S4kfYCi9z4a2IGiNzuJAdgmatTF+yQdRwNtoq+CfgnQGREPpfm5\nFGG3LD14haSRwIt9VJ52qq6LG4GPRcSfYu0FkyuBT7SldO3xGeDhiHgpzQ/EdtGtuy7+BDAA28XB\nwB8j4uWIeAe4CfgkA7NNVNfFPOCTjbSJPgn69JGrU9IeadFBwOPAT4CT07KTgFv6ojzt1ENdLEyN\nt1uPD5pl6ljWHaoYcO2iwjp1MQDbxbPAOElbSRLp54OB2SZq1cUTjbSJvrzrptbDVZsB1wM7AYuB\noyNiRZ8UqI38oNla6frEYoqPol1p2QgGZruoVRezGGDtQtJU4IvAamA+cBowlIHZJirr4hHgdOBq\n6mwTfmDKzCxz/leCZmaZc9CbmWXOQW9mljkHvZlZ5hz0ZmaZc9CbmWXOQW9mljkHvZlZ5v4NTPE3\nfm/JyyYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0eeb2f7d68>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#3. Compare the average, minimum and maximum temperature when you play tennis?\n",
    "played_temp = res[sel(\"temperature\")][res[sel(\"play\")]==\"yes\"]\n",
    "print(\"temperature mean=%f,min=%f,max=%f\"%(played_temp.mean(),played_temp.min(),played_temp.max()))\n",
    "#4. Compare the average, minimum and maximum humidity when you play tennis?\n",
    "played_hum = res[sel(\"humidity\")][res[sel(\"play\")]==\"yes\"]\n",
    "print(\"humidity mean=%f,min=%f,max=%f\"%(played_hum.mean(),played_hum.min(),played_hum.max()))\n",
    "#5. Plot the an scatter plot (x,y diagramm) of humidity (x) and temperatur (y) when you play tennis compared to when you do not play tennis. Use the following lines of code for a plot:\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "plt.figure()\n",
    "plt.plot(res[sel(\"temperature\")],res[sel(\"humidity\")], \"b.\")\n",
    "plt.plot(played_temp,played_hum,\"r*\")\n",
    "plt.title(\"played temperatur vs. played humidity\")\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
